import sys
import glob

if sys.version_info[:2] >= (3, 8):
    # TODO: Import directly (no need for conditional) when `python_requires = >= 3.8`
    from importlib.metadata import PackageNotFoundError, version  # pragma: no cover
else:
    from importlib_metadata import PackageNotFoundError, version  # pragma: no cover

try:
    # dist_name = "common"
    __version__ = '0.1.0' # version(dist_name)
except PackageNotFoundError:  # pragma: no cover
    __version__ = "unknown"
finally:
    del version, PackageNotFoundError


def get_subclasses(cls, level=0):
    '''
    Get all subclasses of a class at a given level.
    level == 0: Get direct subclasses.
    level > 0: Get subclasses, endswith level
    level < 0: Get all subclasses
    '''

    if level == 0:
        return cls.__subclasses__()
    if level > 0:
        return cls.__subclasses__() \
            + [subcls for cls in cls.__subclasses__() for subcls in get_subclasses(cls, level - 1)]
    if level < 0:
        return cls.__subclasses__() \
            + [subcls for cls in cls.__subclasses__() for subcls in get_subclasses(cls, level)]
